﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;


namespace HistoryToMail
{
    public class PluginSettings
    {
        public SMTPSettings smtpSettings = new SMTPSettings();

        public String computerName;

        private int mIdleTime = 1;

        private int mMaxMessages = 0;

        public Boolean logEnable = false;

        public String mailFilterLabel = "IMMessengerHistoryBackUP";

        public int idleTime
        {
            get { return mIdleTime; }
            set
            {
                if (mIdleTime < 0) mIdleTime = 0;
                else if (mIdleTime > 30) mIdleTime = 30;
                else mIdleTime = value;
            }
        }

        public int maxMsgNumberToSend
        {
            get { return mMaxMessages; }
            set
            {
                if (mMaxMessages < 0) mMaxMessages = 0;
                else if (mMaxMessages > 100) mMaxMessages = 100;
                else mMaxMessages = value;
            }
        }

        public void showSettingsDialog()
        {
            PluginSettingsForm dialog = new PluginSettingsForm(this);
            dialog.ShowDialog();
        }

        override public String ToString()
        {
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(this.GetType());
            StringWriter Output = new StringWriter(new StringBuilder());
            x.Serialize(Output, this);
            return Output.ToString();
        }

        public static PluginSettings FromString(String settings)
        {
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(HistoryToMail.PluginSettings));
            StringReader Input = new StringReader(settings);
            return (PluginSettings)x.Deserialize(Input);
        }
    }
}
